//
//  NSArray+Extend.m
//  RMMaterialRed
//
//  Created by XBWH on 2024/3/8.
//

#import "NSArray+Extend.h"

static const NSString *lqq_defaultObject = @"空元素";

@implementation NSArray (Extend)
- (id)lqq_objectAtIndex:(NSUInteger)index{
    if (index < self.count) {
        return [self lqq_objectAtIndex:index];
    }
    return nil;
}
- (id)rb_objectAtIndex:(NSUInteger)index{
    if (index < self.count){
        return self[index];
    }else{
        return nil;
    }
}

@end

@implementation NSMutableArray (Extend)
-(void)lqq_addObject:(id)object {
    if (!object || [object isKindOfClass:[NSNull class]]) {
        [self lqq_addObject:lqq_defaultObject];
    } else {
        [self lqq_addObject:object];
    }
}
- (id)lqq_objectAtIndex:(NSUInteger)index{
    if (index < self.count) {
        return [self lqq_objectAtIndex:index];
    }
    return nil;
}
- (id)rb_objectAtIndex:(NSUInteger)index{
    
    if (index >= [self count]) {
        return nil;
    }
    id value = [self objectAtIndex:index];
    if (value == [NSNull null]) {
        return nil;
    }
    return value;
}
-(void)rb_addObject:(id)object{
    if (!object || [object isKindOfClass:[NSNull class]]) {
        [self addObject:lqq_defaultObject];
    } else {
        [self addObject:object];
    }
    
}
-(void)rb_removeAllObjects{
    if (self.count>0)
    {
        [self removeAllObjects];
    }
}

- (void)rb_removeFirstObject{
    if (self.count) {
        [self removeObjectAtIndex:0];
    }
}
- (void)rb_removeLastObject{
    if (self.count) {
        [self removeObjectAtIndex:self.count - 1];
    }
}
- (void)rb_removeObjectAtIndex:(NSUInteger)index{
    if (index >= [self count]) {
        return ;
    }
    [self removeObjectAtIndex:index];
}
@end
